package com.spring.component.easyexcel.converter;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.spring.component.easyexcel.WeekEnum;

public class WeekEnumConvert implements Converter<WeekEnum> {

  @Override
  public Class supportJavaTypeKey() {
    return String.class;
  }

  @Override
  public CellDataTypeEnum supportExcelTypeKey() {
    return CellDataTypeEnum.STRING;
  }

  @Override
  public WeekEnum convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty,
      GlobalConfiguration globalConfiguration) throws Exception {
    //excel 转化为 java 类型，excel 读时将会被调用
    return WeekEnum.week(cellData.getStringValue());
  }

  @Override
  public CellData convertToExcelData(WeekEnum demoEnum, ExcelContentProperty excelContentProperty,
      GlobalConfiguration globalConfiguration) throws Exception {
    //java 类型转 excel 类型，excel 写时将会被调用
    return new CellData(demoEnum.getCnStr());
  }
}
